<?php
	$deviceToken = $_POST['token'];
echo $deviceToken.'<br>';

//'08cc4452 b50d6556 cb8f2734 7171f420 9bbafdb3 63c98ce3 50c0a8af 93d23ca5';
  
	$body = array("aps" => array("alert" => 'message', "badge" => 2, "sound"=>'default'));
  
	$ctx = stream_context_create();
	stream_context_set_option($ctx, "ssl", "local_cert", "pro.pem");
	$fp = stream_socket_client("ssl://gateway.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
	if (!$fp) {
		print "Failed to connect $err $errstrn";
		return;
	}
	print "Connection OK\n";
	$payload = json_encode($body);
	$msg = chr(0) . pack("n",32) . pack("H*", str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
	print "sending message :" . $payload . "\n";
	fwrite($fp, $msg);
	fclose($fp);
?>

